package com.zx.DataStructuresAndAlgorithms.dao;

import java.util.Random;

/**
 * @Author lovexu
 * @Date 2022/10/22 15:39
 * @ClassName RandTest
 * @Description TODO
 **/
public interface RandTest {
    /**
     * @param arr
     * @param <AnyType> 生产随机的整形类型测试数据
     */
    public static <AnyType extends Comparable<? super AnyType>>
    void randGenerateInteger(AnyType arr[]) {
        Random random = new Random();
        int i;
        for (i = 0; i < arr.length; i++) {
            Integer values = random.nextInt(100);
            arr[i] = (AnyType) values;
        }
        System.out.print("随机生成测试原始数据：");
        for (i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + ",");
        }
        System.out.println();
    }

    /**
     * 生成浮点类型测试数据
     *
     * @param arr
     * @param <AnyType>
     */
    public static <AnyType extends Comparable<? super AnyType>>
    void randGenerateFloat(AnyType arr[]) {
        Random random = new Random();
        Float f1 = -1.3f;
        Float f2 = 10.1f;
        int i;
        for (i = 0; i < arr.length; i++) {
            Float values = f1 + random.nextFloat() * (f2 - f1);
//            Float round = Float.valueOf(Math.round(values));
            arr[i] = (AnyType) values;
        }
        System.out.print("随机生成测试原始数据：");
        for (i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + ",");
        }
        System.out.println();
    }

    /**
     * 生成double类型数据
     *
     * @param arr
     * @param <AnyType>
     */
    public static <AnyType extends Comparable<? super AnyType>>
    void randGenerateDouble(AnyType arr[]) {
        Random random = new Random();
        Double f1 = 1.3;
        Double f2 = 10.6;
        int i;
        for (i = 0; i < arr.length; i++) {
            Double values = f1 + random.nextDouble() * (f2 - f1);
            //Double round = Double.valueOf(Math.round(values));
            arr[i] = (AnyType) values;
        }
        System.out.print("随机生成测试原始数据：");
        for (i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + ",");
        }
        System.out.println();
    }

    /**
     * 字符类型  可以指定某个位置是a-z、A-Z或是0-9
     *
     * @param arr
     * @param <AnyType>
     */
    public static <AnyType extends Comparable<? super AnyType>>
    void randGenerateString(AnyType[] arr) {
        Random random = new Random();
        StringBuffer stringBuffer = new StringBuffer();
        int i;
        for (i = 0; i < arr.length; i++) {
            int values = random.nextInt(3);
            long result = 0;
            switch (values) {
                case 0:
                    result = Math.round(Math.random() * 25 + 65);
                    stringBuffer.append((char) result);

                case 1:
                    result = Math.round(Math.random() * 25 + 97);
                    stringBuffer.append((char) result);
                case 2:
                    stringBuffer.append(new Random().nextInt(10));
                    break;
            }
            String s = stringBuffer.toString();

            arr[i] = (AnyType) s;


        }

        System.out.print("随机生成测试原始数据：");
        for (i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + ",");
        }
        System.out.println();
    }

    /**
     * 生成的字符串每个位置都有可能是str中的一个字母或数字
     *
     * @param arr
     * @param <AnyType>
     */
    public static <AnyType extends Comparable<? super AnyType>>
    void randGenerateStringSingle(AnyType arr[]) {
        String str = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
        Random random = new Random();
        StringBuffer stringBuffer = new StringBuffer();
        int i;
        for (i = 0; i < arr.length; i++) {
            Integer values = random.nextInt(62);
            StringBuffer string = stringBuffer.append(str.charAt(values));
            String s = string.toString();
            arr[i] = (AnyType) s;
        }
        System.out.print("随机生成测试原始数据：");
        for (i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + ",");
        }
        System.out.println();
    }
}

